<?php
    class userclass{
        public $id;
        public $username;
        public $password;
        public $name;
        public $surname;
        public $email;
        public $coupleid;
        public $role;

        function initwithuserid($id){
            require 'phpincludes/dbconnect.php';
            $query = "SELECT * FROM `".$tblusers."` WHERE `id` = '".$id."'";
            $res = mysql_query($query);
            $row = mysql_fetch_assoc($res);
            mysql_close();

            if($row['id'] > 0){
                foreach($row as $key => $val){
                    $this->$key = $val;
                }
            }
        }

        function getpartnerid(){
            require 'phpincludes/dbconnect.php';
            $query = "SELECT * FROM `".$tblusers."` WHERE `id` != '".$this->id."' AND `coupleid` = '".$this->coupleid."' AND `role` = 'couple'";
            $res = mysql_query($query);
            $row = mysql_fetch_assoc($res);
            mysql_close();

            if($row['id'] > 0)
                return $row['id'];
            else
                return 0;
        }
        
        function saveself($test){
            $dbinfo = array('name' => stripslashes($this->name),
                            'surname' => stripslashes($this->surname),
                            'email' => stripslashes($this->email));

            require 'phpincludes/dbconnect.php';

            foreach ($dbinfo as $column => $value)
                $dbinfo[$column] = mysql_real_escape_string($value);

            if($this->id > 0){
                // Profile exists, update using "col1=val1,col2=val2" string
                $i = 0;
                $setpieces = array();
                foreach ($dbinfo as $column => $value){
                    $setpieces[$i] = "`".$column."` = '".$value."'";
                    $i++;
                }
                $sets = implode(", ", $setpieces);

                $query = "UPDATE `".$tbluserprofiles."` SET ".$sets." WHERE `id` = '".$this->id."'";
            }
            
            $res = mysql_query($query);
            mysql_close();
            return $res;
        }
        
        function sendresetmail($lang){
            echo '<br/>';
            echo 'User object<br/>';
            echo '-------------------<br/>';
            echo 'id -> '.$this->id.'<br/>';
            echo 'username -> '.$this->username.'<br/>';
            echo 'password -> '.$this->password.'<br/>';
            echo 'name -> '.$this->name.'<br/>';
            echo 'surname -> '.$this->surname.'<br/>';
            echo 'email -> '.$this->email.'<br/>';
            echo 'coupleid -> '.$this->coupleid.'<br/>';
            echo 'role -> '.$this->role.'<br/>';
        }
        
        function dumpself(){
            echo '<br/>';
            echo 'User object<br/>';
            echo '-------------------<br/>';
            echo 'id -> '.$this->id.'<br/>';
            echo 'username -> '.$this->username.'<br/>';
            echo 'password -> '.$this->password.'<br/>';
            echo 'name -> '.$this->name.'<br/>';
            echo 'surname -> '.$this->surname.'<br/>';
            echo 'email -> '.$this->email.'<br/>';
            echo 'coupleid -> '.$this->coupleid.'<br/>';
            echo 'role -> '.$this->role.'<br/>';
        }
    }
?>
